
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="layout" content="bocMain"/>
    <title>进件作业系统</title>
</head>

<body>

<div class="wxLogin">
    <form controller="login" action="authenticate" method='POST' id='loginForm'>
        <div class="logo">
            <asset:image src="/boc/bank-logo.png" class="weui-media-box__thumb" alt=""/>
            <p>进件作业系统</p>
        </div>
        <div class="weui-cells weui-cells_form">
            <div class="weui-flex weui-login">
                <div class="weui-cell__hd"><label class="weui-label weui-label-img" style="margin-top: -2px"><asset:image src="/boc/tel.png" class="weui-media-box__thumb" alt=""/></label></div>
                <div class="weui-cell__bd">
                    <input class="weui_input weui_input_tel" type="text" placeholder="用户名" required="" value="" name="username" id="username" class="form-control" autofocus="autofocus">
                </div>
            </div>
            <div class="weui-flex weui-login">
                <div class="weui-cell__hd"><label class="weui-label weui-label-img"><asset:image src="/boc/password.png" class="weui-media-box__thumb" alt=""/></label></div>
                <div class="weui-cell__bd">
                    <input class="weui_input weui_input_tel" type="password" placeholder="密码" required="" value="" name="password" id="password" class="form-control">
                </div>
            </div>
        </div>

        <div class="bigBtn">
            <button type="button" class="weui-btn weui-btn_primary" id="submitBtn">立即登录</button>
        </div>
    </form>
</div>
<script>
    $(function () {
        $("#submitBtn").click(function () {
            var username = $("#username").val();
            var password = $("#password").val();
            if (!username)
            {
                helpMessage("请输入用户名");
                return;
            }
            if (!password)
            {
                helpMessage("请输入密码");
                return;
            }
            $.ajax({
                url: "/login/authenticate",
                type: "post",
                data: "username=" + $("#username").val() + "&password=" + $("#password").val(),
                success: function (data) {
                    if (data.success)
                    {
                        location.href = "/bocAppOpportunity/businessManagement";
                    }
                    else
                    {
                        helpMessage('用户名或密码错误，请重试!');
                    }
                },
                error: function (e) {
                    console.log(e)
                    $.ajax({
                        url: "/bocAppOpportunity/isLogIn",
                        type: "post",
                        success: function (data) {
                            if (data.status == 'success')
                            {
                                location.href = "/bocAppOpportunity/businessManagement";
                            }
                            else
                            {
                                helpMessage('用户名或密码错误，请重试!');
                            }
                        },
                        error: function (e) {
                            helpMessage('用户名或密码错误，请重试!');
                        },
                    });
                },
            });
        });
    })

    function helpMessage(message) {
        $(".helpMsg").text(message).fadeIn(200);
        setTimeout(function () {
            $(".helpMsg").fadeOut(200);
        }, 2000);
    }
</script>

</body>
</html>
